package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.logistic.domain.NetworkSheetPriceUnderpay;
import com.ruoyi.logistic.domain.NetworkSheetPriceUnderpayRecord;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.vo.NetworkSheetPriceUnderpayVo;
import com.ruoyi.logistic.mapper.NetworkSheetPriceUnderpayMapper;
import com.ruoyi.logistic.mapper.NetworkSheetPriceUnderpayRecordMapper;
import com.ruoyi.logistic.service.NetworkSheetPriceUnderpayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;
@Service
public class NetworkSheetPriceUnderpayServiceImpl implements NetworkSheetPriceUnderpayService {
    @Autowired
    private NetworkSheetPriceUnderpayMapper networkSheetPriceUnderpayMapper;
    @Autowired
    private NetworkSheetPriceUnderpayRecordMapper networkSheetPriceUnderpayRecordMapper;
    @Override
    public List<NetworkSheetPriceUnderpay> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkSheetPriceUnderpayMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkSheetPriceUnderpay networkSheetPriceUnderpay) {
        return networkSheetPriceUnderpayMapper.insert(networkSheetPriceUnderpay);
    }

    @Override
    public Boolean update(NetworkSheetPriceUnderpay networkSheetPriceUnderpay) {
        NetworkSheetPriceUnderpayRecord record = new NetworkSheetPriceUnderpayRecord();
        record.setContent(networkSheetPriceUnderpay.getSheetFee()+"");
        record.setUnderpayId(networkSheetPriceUnderpay.getId());
        record.setUpdateBy(SecurityUtils.getUserId());
        networkSheetPriceUnderpayRecordMapper.insert(record);
        return networkSheetPriceUnderpayMapper.update(networkSheetPriceUnderpay);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkSheetPriceUnderpayMapper.deleteById(id);
    }

    @Override
    public NetworkSheetPriceUnderpay findById(Integer id) {
        return networkSheetPriceUnderpayMapper.findById(id);
    }

    @Override
    public List<NetworkSheetPriceUnderpay> search(NetworkSheetPriceUnderpayVo networkSheetPriceUnderpayVo) {
        PageHelper.startPage(networkSheetPriceUnderpayVo.getPageDate());
        return networkSheetPriceUnderpayMapper.search(networkSheetPriceUnderpayVo);
    }


    @Override
    public List<NetworkSheetPriceUnderpayRecord> searchDetail(Date startTime, Date endTime, Integer id) {
        return networkSheetPriceUnderpayRecordMapper.search(startTime,endTime,id);
    }
}
